<?php 
//$url = FULL_BASE_URL . Router::url('', false);
$comment_draft = $session->read('comment_draft');	
$here = $this->here;
?>

<div class="comments-embed form" id="comments">
	<h2><?php __('Comments'); ?></h2>
	
	<?php if ($session->check('Message.comments')): ?>
	<p class="message-success"><?php $session->flash('comments');?> </p>
	<?php $session->del('comments');?>
	<?php endif; ?>
	
	<div class="comments-list">
		<?php $comments = $this->requestAction('/comments/latest/' . urlencode($here)); //debug($comments); ?>
		
		<?php if(!empty($comments)):?>
		<?php foreach($comments as $comment):?>
			<?php //debug($comment);?>
		<div class="comments-item">
			<h3 class="attribute-title">
				<?php __('Comment by');?> 
				<?php if( empty($comment['Comment']['url']) ) 
					echo $comment['Comment']['author'];
				else echo $html->link($comment['Comment']['author'], $comment['Comment']['url']); ?>
			</h3>
			<div class="attribute-body">
				<?php echo $textile->TextileRestricted($comment['Comment']['body']); ?>
			</div>
		</div>

		<?php endforeach;?>
		<?php endif;?>
	</div>
	
	<?php echo $form->create('Comment', array('action'=>'embed', 'id'=>'comments-form'));?>
		<fieldset>
			<legend><?php __('Add Comment');?></legend>
		
			<?php if ($session->check('Message.comments_error')): ?>
			<p class="message-error"><?php $session->flash('comments_error');?> </p>
			<?php endif; ?>
		
			<?php echo $form->hidden('ref_url', array('value'=>$here)); ?>
		
			<div class="block">
				<div class="element">
					<?php echo $form->input('author', array('value'=>$comment_draft['Comment']['author'], 'after' => '<p class="description">' . __('You must provide a name', true) . '</p>')); ?>
				</div>
				<div class="element">
					<?php echo $form->input('email', array('value'=>$comment_draft['Comment']['email'], 'after' => '<p class="description">' . __('Please provide your email', true) . '</p>')); ?>
				</div>
			</div>
			<div class="input textarea">
				<?php echo $form->label(__('Your comment', true)); ?>
				<?php echo $form->textarea('body',array('value'=>$comment_draft['Comment']['body'])); ?>
				<p class="description"><?php __('This field can not be left empty'); ?></p>
			</div>
			<?php echo $form->input('url', array('value'=>$comment_draft['Comment']['url'], 'after' => '<p class="description">' . __('Url must start with http://', true) . '</p>')); ?>
			
			<?php $captcha_image_url = $this->webroot.'comments/securimage/'; ?>
			<div class="captcha-holder">
				<?php echo $form->label(__('Captcha code', true)); ?>
				<img src="<?php echo $captcha_image_url; ?>" id="captcha" alt="CAPTCHA Image" onclick="this.src = '<?php echo $captcha_image_url;?>' + Math.random(); return false" title="<?php __('Captcha image - click to generate a new image')?>"/>
				<?php echo $form->text('captcha_code'); ?>
				<p class="help"><?php __('To ensure you are a human, you must enter the word you see in the image here')?>  </p>
				
			</div> 
			
		</fieldset>
	<?php echo $form->end(__('Submit',true));?>
</div>